n = 5
magic_square = [[0] * n for _ in range(n)]

i = 0
j = n // 2

num = 1
while num <= n * n:
    magic_square[i][j] = num
    num += 1
    new_i = (i - 1) % n
    new_j = (j + 1) % n
    if magic_square[new_i][new_j]!= 0:
        i = (i + 1) % n
    else:
        i = new_i
        j = new_j

for row in magic_square:
    for num in row:
        print(format(num, "3d"), end=' ')
    print()